<?php
/**
 * 易优CMS
 * ============================================================================
 * 版权所有 2016-2028 海南赞赞网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.eyoucms.com
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
 * ============================================================================
 * Author: 小虎哥 <1105415366@qq.com>
 * Date: 2018-4-3
 */

namespace app\plugins\controller;

use think\Db;
use weapp\AirBottle\model\AirBottleModel;
use weapp\AirBottle\model\AirFactoryModel;

class AirBottle extends Base
{
    protected $model=null;
    /**
     * 构造方法
     */
    public function __construct(){
        parent::__construct();
        $this->model = new AirBottleModel;
    }

    /**
     * index
     */
    public function index()
    {
        $row = M('weapp')->where('code','eq','AirBottle')->find();
        $data=json_decode($row['data'],true);
        if($this->request->isPost()){
            $code=$this->request->post('code');
            $row=$this->model->where(['code'=>trim($code)])->find();
            if(!$row){
                $this->error("当前编号不存在");
            }
        }else{
            $id=$this->request->param('id');
            $row=$this->model->where(['id'=>intval($id)])->find();
            if(!$row){
                $this->error("未查询到该条记录信息");
            }
        }

        $factory_model=new AirFactoryModel();
        $factory=$factory_model->where(['id'=>1])->find();
        $this->assign('row', $row);
        $this->assign('factory', $factory);
        $this->assign('data', $data);
        return $this->fetch('airbottle/index');
    }
}